class Solution {
    public int[] successfulPairs(int[] spells, int[] potions, long success) {
        int n = spells.length;
        int m = potions.length;
        int[] pairs = new int[n];
        int l, r, mid;
        Arrays.sort(potions);
        for (int i = 0; i < n; i++) {
            l = -1;
            r = m;
            while (l + 1 < r) {
                mid = l + (r - l) / 2;
                if ((long) spells[i] * potions[mid] < success)
                    l = mid;
                else
                    r = mid;
            }
            pairs[i] = m - r;
        }
        return pairs;
    }
}